package org.chen.wordwave.act;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hjq.toast.Toaster;

import org.chen.wordwave.Api.ApiClient;
import org.chen.wordwave.Api.ApiService;
import org.chen.wordwave.R;
import org.chen.wordwave.base.BaseActivity;
import org.chen.wordwave.bean.Reservation;
import org.chen.wordwave.bean.ResultBody;
import org.chen.wordwave.bean.UserInfo;
import org.chen.wordwave.bean.UserRegisterRequest;
import org.chen.wordwave.init.WordInit;
import org.litepal.LitePal;

import java.util.Objects;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class Privacy extends BaseActivity {
    private ApiService apiService;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.privacy);
        TextView tvDeleteAccount = findViewById(R.id.tv_delete_account);
        tvDeleteAccount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDeleteAccountDialog();
            }
        });
        WebView webview = findViewById(R.id.privacy_Agree);
        String language = WordInit.language;
        Log.e("language",language);
        if (language.equals("zh")){
            webview.loadUrl(WordInit.zhPrivacy);
        }else {
            webview.loadUrl(WordInit.enPrivacy);
        }
        apiService = ApiClient.getClient(getApplicationContext()).create(ApiService.class);
    }
    private void showDeleteAccountDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.delete_account)
                .setMessage(R.string.delete_account_confirmation)
                .setPositiveButton(R.string.yes, null)
                .setNegativeButton(R.string.cancle, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .setCancelable(false);
        final AlertDialog dialog = builder.create();
        dialog.show();

        // 获取 "Yes" 按钮并初始时禁用它
        final Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
        positiveButton.setEnabled(false);

        // 创建一个倒计时计时器，每秒更新一次按钮的文字
        new CountDownTimer(10000, 1000) {
            @SuppressLint("SetTextI18n")
            public void onTick(long millisUntilFinished) {
                positiveButton.setText(getString(R.string.yes) + " (" + millisUntilFinished / 1000 + "s)");
            }

            public void onFinish() {
                positiveButton.setText(R.string.yes);
                positiveButton.setEnabled(true);
                // 设置 "Yes" 按钮的点击事件
                positiveButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(Privacy.this, DeleteAccount.class));
                    }
                });
            }
        }.start();

    }

    @Override
    public Integer getLayoutResId() {
        return null;
    }

    @Override
    public void init() {

    }
}

